package servlet.admin;

import entity.Blog;
import service.BlogService;
import service.Impl.BlogServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@WebServlet(urlPatterns = "/admin/BlogAdd")
public class BlogAddServlet extends HttpServlet {
    private BlogService blogService = new BlogServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String title = req.getParameter("title");
        String actionTime = req.getParameter("actionTime");
        String address = req.getParameter("address");
        String peoples = req.getParameter("peoples");
        String event = req.getParameter("event");
        Blog blog = new Blog();
        blog.setActionTime(Date.valueOf(actionTime));
        blog.setTitle(title);
        blog.setAddress(address);
        blog.setPeoples(peoples);
        blog.setEvent(event);
        blogService.save(blog);
        resp.sendRedirect(req.getContextPath() + "/admin/BlogListService");
    }


}
